using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NewAndong.Model;
using NewAndong.Service;
using Leeder.Business;
using Andong.Model;
using Newtonsoft.Json;
using System.Net.WebSockets;

namespace NewAndong.Business
{
    /// <summary>
    /// 
    /// </summary>
   public class BoardBLL : BaseBLL<BoardModel, BoardService>
   {

        SignalLampDirectionService _signalLampDirectionService;

        public BoardBLL()
        {
            Service = new BoardService();
            _signalLampDirectionService = new SignalLampDirectionService();
        }

        public BoardModel GetModel(string name)
        {
            var result = Service.Query(p => p.Name == name);
            if (result.IsSuccess)
            {
                return result.ActivedObj.FirstOrDefault();
            }
            else
            {
                LogObj.Error(result.Dsca);
                return default;
            }
        }

        public List<BoardModel> GetModelById(long id)
        {
            var result = Service.Query(p => p.UnpackingId == id);
            if (result.IsSuccess)
            {
                return result.ActivedObj;
            }
            else
            {
                LogObj.Error(result.Dsca);
                return default;
            }
        }

        //public void SetModel(long unpackingId,string projectName)
        //{
        //    var result = Service.Query(p => p.UnpackingId == unpackingId);
        //    if (!result.IsSuccess)
        //    {
        //        LogObj.Error(result.Dsca);
        //        return;
        //    }
        //    var boardModel = result.ActivedObj.FirstOrDefault();
        //    if (boardModel != null)
        //    {
        //        var statusList = JsonConvert.DeserializeObject<List<AnDongRedisModel>>(boardModel.Value);
        //        foreach (var item in statusList)
        //        {
        //            if (projectName == item.LampName)
        //            {
        //                if (item.Status == 1)
        //                {
        //                    item.Status = 0;
        //                    var getOneInput = new SignalLampDirectionModel();
        //                    getOneInput.LampName = item.LampName;
        //                    var singal = _signalLampDirectionService.GetOne(getOneInput);
        //                    if (singal != null)
        //                    {
        //                        singal.RealDelayCount = "";
        //                        singal.DeliveryStatus = 1;
        //                        _signalLampDirectionService.Update(singal);
        //                    }
        //                    break;
        //                }

        //            }
        //        }
        //        //_redisHelper.HashSet("AnDong", input.UnpackingId.ToString(), JsonConvert.SerializeObject(statusList));
        //        //result.ActivedObj = statusList;

        //        var model = GetModel(unpackingId);
        //        if (model != null)
        //        {
        //            model.Value = JsonConvert.SerializeObject(statusList);
        //            Service.Update(model);
        //        }
        //        else
        //        {
        //            model = new BoardModel();
        //            model.UnpackingId = unpackingId;
        //            model.Value = JsonConvert.SerializeObject(statusList);
        //            Service.Add(model);
        //        }
        //    }
        //}
    }
}
